//
//  FYEmptyOrderView.m
//  fuyoukache
//
//  Created by 于龙 on 15/9/23.
//  Copyright © 2015年 enway-wk. All rights reserved.
//

#import "FYEmptyView.h"

@interface FYEmptyView (){
    
    NSString *_title;
}

@property (nonatomic,strong) CALayer       *backView;
@property (nonatomic,strong) UIImageView  *kimageView;
@property (nonatomic,strong) UILabel      *titleLabel;
@property (copy,nonatomic) NSString *imageName;
@end

@implementation FYEmptyView
static FYEmptyView *_shareInstance=nil;

+ (FYEmptyView *)sharedInstance {
    if (!_shareInstance) {
        
        _shareInstance=[[FYEmptyView alloc] init];
    }
    return _shareInstance;
}

- (void)showEmptyViewOnSuperview:(UIView *)spView WithTitle:(NSString *)title showBtn:(BOOL)show{
    
    if ([spView.layer.sublayers containsObject:self.backView]) {
        return;
    }
    _title = title;
    self.titleLabel.text = _title;

    self.backView.hidden = NO;
    [self.backView setFrame:CGRectMake(0, ((CGRectGetHeight(spView.frame) - 100*DISTENCEH)*.5), kScreenWidth, 100*DISTENCEH)];
//    self.backView.backgroundColor = kRedColor.CGColor;
    [self.backView addSublayer:self.kimageView.layer];
    [self.backView addSublayer:self.titleLabel.layer];
//
//    
//    if (!show) {
//        [self.sendBtn removeFromSuperview];
//    } else
//    {
//        [self.backView addSubview:self.sendBtn];
//
//    }
    [spView.layer addSublayer:self.backView];
}
- (void)showEmptyViewOnSuperview:(UIView *)spView WithTitle:(NSString *)title imageName:(NSString *)imageName
{
    self.imageName = imageName;
    [self showEmptyViewOnSuperview:spView WithTitle:title showBtn:NO];
}
- (CGRect)backViewFrame{
    
    return self.backView.frame;
}

- (void)setNewTitle:(NSString *)title {
    
    _title = title;
    self.titleLabel.text = _title;
}

- (void)emptyViewDissmiss {
    
    self.backView.hidden = YES;
    [self.backView removeFromSuperlayer];
}

- (CALayer*)backView {
    
    if (!_backView) {
        _backView = [[CALayer alloc] init];
    }
    return _backView;
}


- (UIImageView *)kimageView {
    
    if (!_kimageView) {
       
        UIImage *image = [UIImage imageNamed:self.imageName];
        _kimageView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth-image.size.width)/2, 0, image.size.width, image.size.height)];
        [_kimageView setImage:image];
    }
    return  _kimageView;
}

- (UILabel *)titleLabel {
    
    if (!_titleLabel) {
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.kimageView.frame)+10, kScreenWidth, 30)];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = kFontSystem(16);
        _titleLabel.textColor = kColor999999;
    }
    return _titleLabel;
}

- (UIButton *)sendBtn {
    
    if (!_sendBtn) {
        
        _sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _sendBtn.frame = CGRectMake(110, CGRectGetMaxY(self.titleLabel.frame),kScreenWidth-220, 40);
        [_sendBtn setTitle:@"立即发货" forState:UIControlStateNormal];
        [_sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_sendBtn setBackgroundColor:kNavigationTintColor];
        _sendBtn.layer.cornerRadius = kCornerRadius;
        _sendBtn.titleLabel.font = kFontSystem(16);
    }
    return _sendBtn;
}

@end
